﻿using System;

namespace cuiail.DBModels
{


    public class CloudPlatformPosWorkOrder
    {
        /// <summary>
        /// 下发工单
        /// </summary>
        /// 
        public string WorkOrderNumber { get; set; } = "";

        /// <summary>
        /// 产品类型
        /// </summary>
        public string ProductType { get; set; }= "";

        /// <summary>
        /// 产品编号表
        /// </summary>
        public List<DownloadProductInfo> ProductIdTable { get; set; } = new List<DownloadProductInfo>();
    }



    public class CloudPlatPosMode
    {
   
        /// <summary>
        /// 当前工作模式ID，外键关联WorkingMode表
        /// </summary>
        public SystemMode WorkingModeId { get; set; }

    }
    /// <summary>
    ///云平台下发运行命令
    ///
    public class CloudPlatformPosCommand
    {
        /// <summary>
        /// 系统命令
        /// </summary>
        public DeviceRunCommand SystemCommand { get; set; }

        // 时间直接在数据库里下发时创建
    }
    #region 云平台get数据
    ///工单信息，包括工单数据
    //工单开始时间
    //工单结束时间
    //工单完成状态
    //工序1开始时间
    //工序1结束时间
    //工序2开始时间
    //工序2结束时间
    //工序3开始时间
    //工序3结束时间


    public class CloudPlatGetWorkOrderData
    {
        /// <summary>
        /// 工单信息
        /// </summary>
        public string WorkOrderNumber { get; set; } = "";

        /// <summary>
        /// 产品类型
        /// </summary>
        public string ProductType { get; set; } = "";

        /// <summary>
        /// 产品编号表
        /// </summary>
        public List<UploadProductTraceInfo> ProductIdTable { get; set; } = new List<UploadProductTraceInfo>();
        /// <summary>
        /// 工单开始时间
        /// </summary>
        public DateTime WorkOrderStartTime { get; set; }

        /// <summary>
        /// 工单结束时间
        /// </summary>
        public DateTime WorkOrderEndTime { get; set; }

        /// <summary>
        /// 工单完成状态，未开始，进行中，暂停，已完成。
        /// </summary>
        public string WorkOrderCompletionStatus { get; set; }

        //寻找工单的第一个未开始的产品信息编号
       public int FindFirstNotStartedProductIndex()
        {
            for (int i = 0; i < ProductIdTable.Count; i++)
            {
                if (ProductIdTable[i].ProcessStatus.ProcessId== 0 &&
                   ProductIdTable[i].IsProcessingComplete ==false)
                {
                    return i;
                }
            }
            return -1; // 如果所有产品都已开始，返回-1
        }
       //判断产品id是否是最后一个
       public bool IsLastProduct(string productId)
        {
            if (ProductIdTable.Count == 0)
                return false;
            return ProductIdTable[ProductIdTable.Count - 1].ProductId == productId;
        }

        public void InitFromPosdata(CloudPlatformPosWorkOrder temp)
        {
            WorkOrderNumber = temp.WorkOrderNumber;
            ProductType = temp.ProductType;
            ProductIdTable.Clear();
            WorkOrderCompletionStatus ="未开始";
        }

    }
    //质检岛状态数据
    //设备状态    int
    //质检通过    结构体
    //基材仓物品数量 int
    //剩余U盘数量  int
    //成品仓物品数量 int
    //相机1运行状态 string
    //相机2运行状态 string
    //相机3运行状态 string
    //相机1定位完成 bool
    //相机2定位完成 bool
    //相机2定位完成 bool
    //计算定位偏移量 不给
    //机械臂1运行状态    string
    //机械臂2运行状态    string
    //机械臂末端执行器当前位置    结构体
    //机械臂1请求定位    bool
    //机械臂2请求定位    bool
    //机械臂取料完成 bool
    //机械臂放料完成 bool
    //当前装配状态  结构体
    //故障反馈    结构体
    //模式状态    int
    //满仓信号    bool
    public class CloudPlatGetInspectionIslandStatusData
    {
        /// <summary>
        /// 设备状态
        /// </summary>
        public DeviceRunStatus EquipmentStatus { get; set; }

        /// <summary>
        /// 质检通过
        /// </summary>
        public QualityInspectionResult InspectionPassed { get; set; }

        /// <summary>
        /// 缺陷类型
        /// </summary>
        public int DefectType { get; set; }
        /// <summary>
        /// 剩余U盘数量
        /// </summary>
        public int RemainingUsbDrives { get; set; }

        /// <summary>
        /// 成品仓物品数量
        /// </summary>
        public int FinishedProductStorageQuantity { get; set; }

        /// <summary>
        /// 相机1运行状态
        /// </summary>
        public int Camera1Status { get; set; }

   
        /// <summary>
        /// 相机1定位完成
        /// </summary>
        public bool Camera1PositioningCompleted { get; set; }

     

        /// <summary>
        /// 机械臂1运行状态
        /// </summary>
        public int RobotArm1Status { get; set; }

     

        /// <summary>
        /// 机械臂末端执行器当前位置
        /// </summary>
        public RobotEndPose Robot1EndEffectorCurrentPosition { get; set; }
 
        /// <summary>
        /// 机械臂1请求定位
        /// </summary>
        public bool RobotArm1PositioningRequested { get; set; }

      

        /// <summary>
        /// 机械臂取料完成
        /// </summary>
        public bool RobotArmPickupCompleted { get; set; }

        /// <summary>
        /// 机械臂放料完成
        /// </summary>
        public bool RobotArmPlacementCompleted { get; set; }

        /// <summary>
        /// 当前装配状态
        /// </summary>
        public CurrentProcessInfo CurrentAssemblyStatus { get; set; }

        /// <summary>
        /// 故障反馈
        /// </summary>
        public ErrorInfo FaultFeedback { get; set; }

        /// <summary>
        /// 模式状态
        /// </summary>
        public SystemMode ModeStatus { get; set; }

        /// <summary>
        /// 满仓信号
        /// </summary>
        public bool StorageFullSignal { get; set; }

        /// <summary>
        /// 镭雕状态
        /// </summary>
        public int LaserEngravingStatus { get; set; }

        /// <summary>
        /// 视觉软件状态
        /// </summary>
        /// 
        public int VisionSoftwareStatus { get; set; }
        public CloudPlatGetInspectionIslandStatusData()
        {
        }
        public CloudPlatGetInspectionIslandStatusData(_质检岛_POS_状态 temp)
        {
            EquipmentStatus = temp._设备状态;
            InspectionPassed = temp._质检通过;
            DefectType = temp._缺陷类型;
            RemainingUsbDrives = temp._剩余U盘数量;
            FinishedProductStorageQuantity = temp._成品仓物品数量;
            Camera1Status = temp._相机1运行状态;
        
            Camera1PositioningCompleted = temp._相机1定位完成;

            RobotArm1Status = temp._机械臂1运行状态;
      
            Robot1EndEffectorCurrentPosition = temp._机械臂末端执行器当前位置;
            RobotArm1PositioningRequested = temp._机械臂1请求定位;
         
            RobotArmPickupCompleted = temp._机械臂取料完成;
            RobotArmPlacementCompleted = temp._机械臂放料完成;
            CurrentAssemblyStatus = temp._当前工序状态;
            FaultFeedback = temp._故障反馈;
            ModeStatus = temp._模式状态;
            StorageFullSignal = temp._满仓信号;
            LaserEngravingStatus = temp._镭雕状态;
            VisionSoftwareStatus = temp._视觉软件状态;
        }
        public void Updatefrom质检岛_POS_状态(_质检岛_POS_状态 temp)
        {
            EquipmentStatus = temp._设备状态;
            InspectionPassed = temp._质检通过;
            DefectType = temp._缺陷类型;
            RemainingUsbDrives = temp._剩余U盘数量;
            FinishedProductStorageQuantity = temp._成品仓物品数量;
            Camera1Status = temp._相机1运行状态;
      
            Camera1PositioningCompleted = temp._相机1定位完成;
         
            RobotArm1Status = temp._机械臂1运行状态;
      
            Robot1EndEffectorCurrentPosition = temp._机械臂末端执行器当前位置;
            RobotArm1PositioningRequested = temp._机械臂1请求定位;
           
            RobotArmPickupCompleted = temp._机械臂取料完成;
            RobotArmPlacementCompleted = temp._机械臂放料完成;
            CurrentAssemblyStatus = temp._当前工序状态;
            FaultFeedback = temp._故障反馈;
            ModeStatus = temp._模式状态;
            StorageFullSignal = temp._满仓信号;
            LaserEngravingStatus = temp._镭雕状态;
            VisionSoftwareStatus = temp._视觉软件状态;
        }
    }

    //    装配岛状态数据
    //设备状态
    //零件已装配数量
    //仓库零件1数量
    //仓库零件2数量
    //仓库零件3数量
    //仓库零件4数量
    //仓库基板数量
    //成品仓物品数量
    //相机1运行状态
    //相机2运行状态
    //相机3运行状态
    //定位偏移量
    //机械臂1运行状态
    //机械臂2运行状态
    //机械臂末端执行器当前位置
    //机械臂1请求定位
    //机械臂2请求定位
    //机械臂取料完成
    //机械臂放料完成
    //当前装配状态
    //故障反馈
    //模式状态

    public class CloudPlatGetAssemblyIslandStatusData
    {
        /// <summary>
        /// 设备状态
        /// </summary>
        public DeviceRunStatus EquipmentStatus { get; set; } = DeviceRunStatus.Paused;

        /// <summary>
        /// 零件已装配数量
        /// </summary>
        public int AssembledPartsCount { get; set; }

        /// <summary>
        /// 仓库零件1数量
        /// </summary>
        public int WarehousePart1Quantity { get; set; }

        /// <summary>
        /// 仓库零件2数量
        /// </summary>
        public int WarehousePart2Quantity { get; set; }

        /// <summary>
        /// 仓库零件3数量
        /// </summary>
        public int WarehousePart3Quantity { get; set; }

        /// <summary>
        /// 仓库零件4数量
        /// </summary>
        public int WarehousePart4Quantity { get; set; }

        /// <summary>
        /// 仓库基板数量
        /// </summary>
        public int WarehouseSubstrateQuantity { get; set; }

     

        /// <summary>
        /// 相机1运行状态
        /// </summary>
        public int Camera1Status { get; set; } 

        /// <summary>
        /// 相机2运行状态
        /// </summary>
        public int Camera2Status { get; set; } 

        /// <summary>
        /// 相机3运行状态
        /// </summary>
        public int Camera3Status { get; set; }

        /// <summary>
        /// 定位偏移量
        /// </summary>
        public PositionOffset PositioningOffset { get; set; } = new PositionOffset();

        /// <summary>
        /// 机械臂1运行状态
        /// </summary>
        public int RobotArm1Status { get; set; }

        /// <summary>
        /// 机械臂2运行状态
        /// </summary>
        public int RobotArm2Status { get; set; }

        /// <summary>
        /// 机械臂末端执行器当前位置
        /// </summary>
        public RobotEndPose Robot1EndEffectorPosition { get; set; } = new RobotEndPose();
        /// <summary>
        /// 机械臂末端执行器当前位置
        /// </summary>
        public RobotEndPose Robot2EndEffectorPosition { get; set; } = new RobotEndPose();
        /// <summary>
        /// 机械臂1请求定位
        /// </summary>
        public bool IsRobotArm1PositioningRequested { get; set; }

        /// <summary>
        /// 机械臂2请求定位
        /// </summary>
        public bool IsRobotArm2PositioningRequested { get; set; }

        /// <summary>
        /// 机械臂1取料完成
        /// </summary>
        public bool IsRobot1ArmPickupCompleted { get; set; }

        /// <summary>
        /// 机械臂1放料完成
        /// </summary>
        public bool IsRobot1ArmPlacementCompleted { get; set; }

        /// <summary>
        /// 当前装配状态
        /// </summary>
        public CurrentProcessInfo CurrentAssemblyStatus { get; set; } = new CurrentProcessInfo();

        /// <summary>
        /// 故障反馈
        /// </summary>
        public ErrorInfo FaultFeedback { get; set; } = new ErrorInfo();

        /// <summary>
        /// 模式状态
        /// </summary>
        public SystemMode ModeStatus { get; set; } = 0;
        /// <summary>
        /// 振动盘状态
        /// </summary>
        public int VibratoryDiskStatus { get; set; } = 0;

        public CloudPlatGetAssemblyIslandStatusData()
        {
        }
        public CloudPlatGetAssemblyIslandStatusData(_装配岛_POS_状态 temp)
        {
            EquipmentStatus = temp._设备状态;
            AssembledPartsCount = temp._零件已装配数量;
            WarehousePart1Quantity = temp._仓库零件1数量;
            WarehousePart2Quantity = temp._仓库零件2数量;
            WarehousePart3Quantity = temp._仓库零件3数量;
            WarehousePart4Quantity = temp._仓库零件4数量;
            WarehouseSubstrateQuantity = temp._仓库基板数量;
       
            Camera1Status = temp._相机1运行状态;
            Camera2Status = temp._相机2运行状态;
            Camera3Status = temp._相机3运行状态;
            PositioningOffset = temp._定位偏移量;
            RobotArm1Status = temp._机械臂1运行状态;
            RobotArm2Status = temp._机械臂2运行状态;
            Robot1EndEffectorPosition = temp._机械臂1末端执行器当前位置;
            Robot2EndEffectorPosition = temp._机械臂2末端执行器当前位置;
            IsRobotArm1PositioningRequested = temp._机械臂1请求定位;
            IsRobotArm2PositioningRequested = temp._机械臂2请求定位;
            IsRobot1ArmPickupCompleted = temp._机械臂取料完成;
            IsRobot1ArmPlacementCompleted = temp._机械臂放料完成;
            CurrentAssemblyStatus = temp._当前工序状态;
            FaultFeedback = temp._故障反馈;
            ModeStatus = temp._模式状态;
            VibratoryDiskStatus =temp._振动盘状态;
        }
        public void Updatefrom装配岛_POS_状态(_装配岛_POS_状态 temp)
        {
            EquipmentStatus = temp._设备状态;
            AssembledPartsCount = temp._零件已装配数量;
            WarehousePart1Quantity = temp._仓库零件1数量;
            WarehousePart2Quantity = temp._仓库零件2数量;
            WarehousePart3Quantity = temp._仓库零件3数量;
            WarehousePart4Quantity = temp._仓库零件4数量;
            WarehouseSubstrateQuantity = temp._仓库基板数量;
    
            Camera1Status = temp._相机1运行状态;
            Camera2Status = temp._相机2运行状态;
            Camera3Status = temp._相机3运行状态;
            PositioningOffset = temp._定位偏移量;
            RobotArm1Status = temp._机械臂1运行状态;
            RobotArm2Status = temp._机械臂2运行状态;
            Robot1EndEffectorPosition = temp._机械臂1末端执行器当前位置;
            Robot2EndEffectorPosition = temp._机械臂2末端执行器当前位置;
            IsRobotArm1PositioningRequested = temp._机械臂1请求定位;
            IsRobotArm2PositioningRequested = temp._机械臂2请求定位;
            IsRobot1ArmPickupCompleted = temp._机械臂取料完成;
            IsRobot1ArmPlacementCompleted = temp._机械臂放料完成;
            CurrentAssemblyStatus = temp._当前工序状态;
            FaultFeedback = temp._故障反馈;
            ModeStatus = temp._模式状态;
            VibratoryDiskStatus =temp._振动盘状态;
        }
    }



    //搬运机器人状态数据
    //    设备状态

    //    设备当前位置
    //    设备当前工序步

    //    当前工序状态
    //    故障反馈

    //    模式状态
    public class CloudPlatGetTransportRobotStatusData
    {
        /// <summary>
        /// 设备状态
        /// </summary>
        public DeviceRunStatus EquipmentStatus { get; set; } = DeviceRunStatus.Paused;

        /// <summary>
        /// 设备当前位置
        /// </summary>
        public MobileRobotPose CurrentPosition { get; set; } = new MobileRobotPose();

        /// <summary>
        /// 设备当前工序步
        /// </summary>
        public int CurrentProcessStep { get; set; }

        /// <summary>
        /// 当前工序状态
        /// </summary>
        public CurrentProcessInfo CurrentProcessStatus { get; set; } = new CurrentProcessInfo();

        /// <summary>
        /// 故障反馈
        /// </summary>
        public ErrorInfo FaultFeedback { get; set; } = new ErrorInfo();

        /// <summary>
        /// 模式状态
        /// </summary>
        public SystemMode ModeStatus { get; set; } = 0;
        
        public CloudPlatGetTransportRobotStatusData()
        {
        }
        public CloudPlatGetTransportRobotStatusData(_搬运机器人_POS_状态 temp)
        {
            EquipmentStatus = temp._设备状态;
            CurrentPosition = temp._设备当前位置;
            CurrentProcessStep = temp._设备当前工序步;
            CurrentProcessStatus = temp._当前工序状态;
            FaultFeedback = temp._故障反馈;
            ModeStatus = temp._模式状态;
        }
        public void Updatefrom搬运机器人_POS_状态(_搬运机器人_POS_状态 temp)
        {
            EquipmentStatus = temp._设备状态;
            CurrentPosition = temp._设备当前位置;
            CurrentProcessStep = temp._设备当前工序步;
            CurrentProcessStatus = temp._当前工序状态;
            FaultFeedback = temp._故障反馈;
            ModeStatus = temp._模式状态;
        }

    }

    //巡检机器人状态数据
    //巡检机器人状态数据
    //设备状态    int
    //检修开始时间  datatime
    //检修结束时间  datetime
    //故障设备    string
    //故障设备位置  预留
    //故障类型描述  string
    //异常指标    预留
    //建议修复方案  string
    //是否智能修复  bool
    //是否派人修复  bool
    //进度  double
    //修复开始时间  datetime
    //修复结束时间  datetime
    //故障是否修复  bool
    //巡检机器人状态 bool
    //巡检机器人坐标 bool
    //设备故障反馈  结构体
    //模式状态    int
    public class CloudPlatGetInspectionRobotStatusData
    {
        /// <summary>
        /// 设备状态
        /// </summary>
        public DeviceRunStatus EquipmentStatus { get; set; }

        /// <summary>
        /// 检修开始时间
        /// </summary>
        public DateTime MaintenanceStartTime { get; set; }

        /// <summary>
        /// 检修结束时间
        /// </summary>
        public DateTime MaintenanceEndTime { get; set; }

        /// <summary>
        /// 故障设备
        /// </summary>
        public string FaultyEquipment { get; set; }

        /// <summary>
        /// 故障设备位置
        /// </summary>
        public string FaultyEquipmentLocation { get; set; }

        /// <summary>
        /// 故障类型描述
        /// </summary>
        public string FaultTypeDescription { get; set; }

        /// <summary>
        /// 建议修复方案
        /// </summary>
        public string SuggestedRepairSolution { get; set; }

        /// <summary>
        /// 是否智能修复
        /// </summary>
        public bool CanAutoRepair { get; set; }

        /// <summary>
        /// 是否派人修复
        /// </summary>
        public bool RequiresManualRepair { get; set; }

        /// <summary>
        /// 进度
        /// </summary>
        public double Progress { get; set; }

        /// <summary>
        /// 修复开始时间
        /// </summary>
        public DateTime RepairStartTime { get; set; }

        /// <summary>
        /// 修复结束时间
        /// </summary>
        public DateTime RepairEndTime { get; set; }

        /// <summary>
        /// 故障是否修复
        /// </summary>
        public bool IsFaultRepaired { get; set; }

        /// <summary>
        /// 巡检机器人坐标
        /// </summary>
        public MobileRobotPose InspectionRobotPosition { get; set; }

        /// <summary>
        /// 设备故障反馈
        /// </summary>
        public ErrorInfo EquipmentFaultFeedback { get; set; }

        /// <summary>
        /// 模式状态
        /// </summary>
        public SystemMode ModeStatus { get; set; }

        public CloudPlatGetInspectionRobotStatusData()
        {
        }
        public CloudPlatGetInspectionRobotStatusData(_巡检机器人_POS_状态 temp)
        {
            EquipmentStatus = temp._设备状态;
            MaintenanceStartTime = temp._检修开始时间;
            MaintenanceEndTime = temp._检修结束时间;
            FaultyEquipment = temp._故障设备;
            FaultyEquipmentLocation = temp._故障设备位置;
            FaultTypeDescription = temp._故障类型描述;
            SuggestedRepairSolution = temp._建议修复方案;
            CanAutoRepair = temp._是否智能修复;
            RequiresManualRepair = temp._是否派人修复;
            Progress = temp._进度;
            RepairStartTime = temp._修复开始时间;
            RepairEndTime = temp._修复结束时间;
            IsFaultRepaired = temp._故障是否修复;
            InspectionRobotPosition = temp._巡检机器人坐标;
            EquipmentFaultFeedback = temp._设备故障反馈;
            ModeStatus = temp._模式状态;
        }
        public void Updatefrom巡检机器人_POS_状态(_巡检机器人_POS_状态 temp)
        {
            EquipmentStatus = temp._设备状态;
            MaintenanceStartTime = temp._检修开始时间;
            MaintenanceEndTime = temp._检修结束时间;
            FaultyEquipment = temp._故障设备;
            FaultyEquipmentLocation = temp._故障设备位置;
            FaultTypeDescription = temp._故障类型描述;
            SuggestedRepairSolution = temp._建议修复方案;
            CanAutoRepair = temp._是否智能修复;
            RequiresManualRepair = temp._是否派人修复;
            Progress = temp._进度;
            RepairStartTime = temp._修复开始时间;
            RepairEndTime = temp._修复结束时间;
            IsFaultRepaired = temp._故障是否修复;
            InspectionRobotPosition = temp._巡检机器人坐标;
            EquipmentFaultFeedback = temp._设备故障反馈;
            ModeStatus = temp._模式状态;
        }
    }

    #endregion


}

